package org.gwt.mosaic.samples.addressbook.client.ui;

import org.gwt.mosaic.application.client.util.ApplicationFramework;
import org.gwt.mosaic.forms.client.builder.ButtonStackBuilder;
import org.gwt.mosaic.forms.client.builder.DefaultFormBuilder;
import org.gwt.mosaic.forms.client.layout.CellConstraints;
import org.gwt.mosaic.forms.client.layout.FormLayout;
import org.gwt.mosaic.ui.client.InfoPanel;
import org.gwt.mosaic.ui.client.LayoutComposite;
import org.gwt.mosaic.ui.client.InfoPanel.InfoPanelType;
import org.gwt.mosaic.ui.client.layout.LayoutPanel;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.TextBox;

public class ContactForm extends LayoutComposite {

  private final TextBox firstNameInput = new TextBox();
  private final TextBox lastNameInput = new TextBox();
  private final TextBox emailInput = new TextBox();

  public ContactForm() {
    super(new FormLayout("fill:100dlu:grow, 6dlu, p", "fill:56dlu:grow"));

    final DefaultFormBuilder formBuilder = new DefaultFormBuilder(
        new FormLayout("right:pref, 3dlu, fill:pref:grow"));

    formBuilder.append("First Name:", firstNameInput);
    formBuilder.append("Last Name:", lastNameInput);
    formBuilder.append("Email:", emailInput);

    final ButtonStackBuilder btnBuilder = new ButtonStackBuilder();
    btnBuilder.addGridded(new Button("Update List", new ClickHandler() {
      public void onClick(ClickEvent event) {
        InfoPanel.show(InfoPanelType.HUMANIZED_MESSAGE, Window.getTitle(),
            "Under construction ;-)");
      }
    }));
    btnBuilder.addRelatedGap();
    btnBuilder.addGridded(new Button("Cancel", new ClickHandler() {
      public void onClick(ClickEvent event) {
        InfoPanel.show(InfoPanelType.HUMANIZED_MESSAGE, Window.getTitle(),
            "Under construction ;-)");
      }
    }));
    btnBuilder.addUnrelatedGap();
    btnBuilder.addGridded(ApplicationFramework.newToolButton("helpCmd"));
    btnBuilder.addUnrelatedGap();

    final LayoutPanel layoutPanel = getLayoutPanel();
    layoutPanel.add(formBuilder.getPanel(), CellConstraints.xy(1, 1));
    layoutPanel.add(btnBuilder.getPanel(), CellConstraints.xy(3, 1));

    addStyleName("ContactForm");
  }

  /**
   * @return the firstNameInput
   */
  public TextBox getFirstNameInput() {
    return firstNameInput;
  }

  /**
   * @return the lastNameInput
   */
  public TextBox getLastNameInput() {
    return lastNameInput;
  }

  /**
   * @return the emailInput
   */
  public TextBox getEmailInput() {
    return emailInput;
  }

}
